package com.lb.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lb.common.Result;
import com.lb.entity.Dish;
import com.lb.entity.Query;
import com.lb.entity.Student;
import com.lb.service.dishservice;
import com.lb.service.impel.DishServiceimpel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@CrossOrigin
@Slf4j
public class dishcontroller {
        @Autowired
        private dishservice dishService;
        @PostMapping("/dish/all")
        public Result getall(@RequestBody Query query)
        {
                Page<Dish> bypage = dishService.getBypage(query);
                return Result.success(bypage);
                //List<Dish> list = dishService.list();
               // return Result.success(list);
        }
        @GetMapping("/dishes")
        public Result getByName(@RequestParam String categoryId)
        {
                QueryWrapper<Dish> wrapper = new QueryWrapper<>();
                wrapper.eq("categoryid", categoryId);
                List<Dish> list = dishService.list(wrapper);
                return Result.success(list);
        }
         @GetMapping("/dish/detailById")
        public Result getById(@RequestParam Integer dishId)
         {
                 QueryWrapper<Dish> wrapper = new QueryWrapper<>();
                 wrapper.eq("dishid", dishId);
                 Dish one = dishService.getOne(wrapper);
           return Result.success(one);
          }
          @GetMapping("/dish/getByname")
          public Result getByName1(@RequestParam String dishName)
          {
                  QueryWrapper<Dish> wrapper = new QueryWrapper<>();
                  wrapper.eq("dishname", dishName);
                  Dish dish = dishService.getOne(wrapper);
                 return Result.success(dish);
          }
}
